package thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author Administrator
 * @Date 2020/5/14
 * @Description:
 */
public class CyclicBarrierDemo extends Thread{
    private static CyclicBarrier cyclicBarrier = new CyclicBarrier(5);

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new CyclicBarrierDemo().start();
        }
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "启动");
        try {
            System.out.println(Thread.currentThread().getName() + "等待。。。。。");
            int await = cyclicBarrier.await();
            System.out.println(Thread.currentThread().toString() + await);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "执行完成");
    }
}
